package exam;

import java.util.Scanner;

/**
 * @author DengYuan2
 * @create 2021-03-27 19:37
 */
public class Y1 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int total = Integer.parseInt(scanner.nextLine());
        for (int i = 0; i < total; i++) {
            String group= scanner.nextLine();
            String[] s = group.split(" ");
            int len=Integer.parseInt(s[0]);
            int time=0;
            for (int j = 1; j < len; j++) {
                int x = Integer.parseInt(s[j]);
                if (x<Integer.parseInt(s[j+1])){
                    time++;
                }
            }
            if (Integer.parseInt(s[1])>Integer.parseInt(s[len])){
                time++;
            }
            if (time<2){
                System.out.println("Y");
            }else {
                System.out.println("N");
            }
        }
    }

}
